<%@ page import="com.devicemantra.coordinate.dataobjects.*,java.util.*,com.google.appengine.api.datastore.KeyFactory" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<script type="text/javascript" src="/js/jquery.js"></script> 
<script type="text/javascript" src="/js/jquery.corner.js"></script> 
<link rel="stylesheet" type="text/css" href="/css/tab.css" />
<link rel="stylesheet" type="text/css" href="/css/navigation.css" />
<script type="text/javascript">
function initXMLHttpClient() 
{
     var xmlhttp;
     try {
         // Mozilla / Safari / IE7
         xmlhttp = new XMLHttpRequest();
     } 
     catch (e) 
     {
          // IE
          var XMLHTTP_IDS = new Array('MSXML2.XMLHTTP.5.0',
                                     'MSXML2.XMLHTTP.4.0',
                                     'MSXML2.XMLHTTP.3.0',
                                     'MSXML2.XMLHTTP',
                                     'Microsoft.XMLHTTP' );
        var success = false;
          for (var i=0;i < XMLHTTP_IDS.length && !success; i++) 
	  {
              try 
	    	{
                   xmlhttp = new ActiveXObject(XMLHTTP_IDS[i]);
                      success = true;
                } catch (e) {}
          }
          if (!success) 
	  {
              throw new Error('Unable to create XMLHttpRequest.');
          }
      }
     return xmlhttp;
}

function dept_clicked(linkObj)
{
	alert(linkObj);
	
}

function test_parent(message)
{
	//alert(message);
	document.getElementById('message').innerHTML = message;
}

function init()
{
	document.getElementById('file_upload_form').onsubmit=function() {
	alert("init called now");
	document.getElementById('file_upload_form').target = 'upload_target'; //'upload_target' is the name of the iframe
	} 
}

function js_clicked()
{
	//alert("clicked called now");
	document.getElementById('message').innerHTML = "Processing....";
	//alert(document.upload.dept_name.name);
	document.add_dept_form.submit();
}

function js_add_department()
{
	//alert("Called");
	var httpGetReq = initXMLHttpClient();
	httpGetReq.onreadystatechange =function() 
	{
		if(httpGetReq.readyState == 4)
   		{
        		if (httpGetReq.status==200)
        		{
          		//alert(httpGetReq.responseText);
          		//document.getElementById('anim_window').innerHTML = "";
          		document.getElementById('show_window').innerHTML = httpGetReq.responseText;
			}
		}
	}
	
	//alert("GET'ing getWindow.jsp?category=subdepartment&department=" + lSelectBox.options[lSelectBox.selectedIndex].text);
	httpGetReq.open("GET","/modules/administration/add_dept.jsp",true);
	httpGetReq.send(null);
	document.getElementById('show_window').innerHTML = "<img src=\"images/animation.gif\" alt=\"Processing...\" />"; 
}


</script>	
<style type="text/css">
.box {
background-color :#E2E2E2;
margin:15px;
padding:5px;
}
</style> 

<script>
$(document).ready(
function () 
{
	//alert("markers rounding function called");
	$("div.box").corner(); 
	//$("#map").corner("bevel 4px");
	//$("#selected_box").corner();
	//$("#enable_marking").hide();
	//$("#map").fadeIn(3000);
	//$("#testbox").fadeIn(3000);
	
}
);
</script>


</head>
<body>
<ul id="tabmenu">
	<li><a href="/AdminController?id=country" onclick="dept_clicked(this.text); return false">Country</a></li>
	<li><a  href="/AdminController?id=states">States</a></li>
	<li><a class="active" href="/AdminController?id=department">Department</a></li>
	<li><a href="/AdminController?id=users">Users</a></li>
</ul>

<div class="box" style="width:400px;">
<div id="show_window" style="width:400px; height:250px;">
<%
	System.out.println("Inside department.jsp");
	List<CDepartment> lListOfDepts = CDepartmentFactory.getAllDepartments();
	Iterator<CDepartment> lCDepartmentIter = lListOfDepts.iterator();
	out.print("<br><br>");
	out.print("<TABLE ALIGN=left BORDER=0 BGCOLOR=000000>");
		
	int counter = 3;
	while( lCDepartmentIter.hasNext())
	{
		 if( (counter % 3 ) == 0) 
		 {
			 	out.print("<TR>");
			 	
		 }
			 counter++;
			 CDepartment lDept = lCDepartmentIter.next();
			 out.print("<TD><A value=\"" + lDept.getDepartmentName() + "\"" +  " id=\"" + lDept.getDepartmentName() + "\"" + " href=\"/ViewDepartment?name=" +    lDept.getDepartmentName() +  "\"" + " > " + lDept.getDepartmentName() + " </A>    " + "<IMG SRC=\"/getImage?image_key=" + lDept.getLogo().getKey() + "\" />" +  " </TD>");
			 
			 if( (counter % 3 ) == 0)
			 {
			 	out.print("</TR>");
			 }
			 
	}
	 out.print("<TR><TD> <input type=submit onclick=\"js_add_department()\" value=\"Add CDepartment\">" + "</TD></TR>");
	 out.print("</TABLE>");
%>		
<div id="message"></div>
</div>
</div>
</body>
</html>
